<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.jspsmart.upload.SmartUpload" %> 
<%@ page import="com.jspsmart.upload.*"%>
<%@ page import="com.jspsmart.upload.File"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>上传图片</title>

</head>


<body>
<% 
SmartUpload smart = new SmartUpload();
smart.initialize(pageContext) ;    // 初始化上传操作
smart.upload();     // 上传准备

String rootPath;
//取得客户端的网络地址
String remoteAddr = request.getRemoteAddr();
//获得服务器的名字
String serverName = request.getServerName();

//取得互联网程序的绝对地址
String realPath = request.getRealPath(serverName);
realPath = realPath.substring(0,realPath.lastIndexOf("\\"));
//创建文件的保存目录
rootPath = realPath + "\\tupian\\";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//载入驱动程序类别
String url="jdbc:odbc:shangchuantupian";
String user="";
String pwd="";//建立数据库链接，stuDataBase为ODBC数据源名称
Connection con=DriverManager.getConnection(url,user,pwd);
//Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//建立ResultSet(结果集)对象,并执行sql语句

	smart.save(rootPath);    // 文件保存
	String tupian01=smart.getFiles().getFile(0).getFileName();
	
	if(tupian01==null||tupian01.equals(""))
		{
		%> 
		<script type="text/javascript">
			alert("请选择一张图片",window.location.href="FaBu.jsp");
		</script>
		<%
		}
	else
	{
		
		Statement sql=null;
		sql=con.createStatement();
		String condition="insert into tupian(tupianmingzi) values"+"("+"'"+tupian01+"')";
		sql.executeUpdate(condition);
		
		%>
		<script type="text/javascript">
			alert("恭喜，图片上传成功！点击确定查看所有图片",window.location.href="FaBu03.jsp");
		</script>
		<%
	}
%>
</body>
</html>